<template>
  <div class="app-container">
    <div style="text-align: center">{{createStatus?'添加':'更新'}}消防隐患</div>
    <div style="width: 50%;margin:0px auto;vertical-align:middle;height:100%">
      <el-form :model="hiddenDangerFrom" ref="hiddenDangerFrom" :rules="hiddenDangerFromRules" label-width="100px">
        <el-form-item label="所属企业" prop="enterpriseId" >
          <el-select v-model="hiddenDangerFrom.enterpriseId" placeholder="请选择责任企业" style="width: 100%" v-if="enterPriseHidden">
            <el-option v-for="(item,index) in enterpriseList" :key="index"  :value="item.ucId" :label="item.name" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="hiddenDangerFrom.name" placeholder="请输入名称" style="width: 100%"></el-input>
        </el-form-item>
        <el-form-item label="地点" prop="address">
          <el-input v-model="hiddenDangerFrom.address" placeholder="请输入地点" style="width: 100%"></el-input>
        </el-form-item>
<!--        <el-form-item label="异常图片" prop="abnormalPic">-->
<!--          <el-input v-model="hiddenDangerFrom.abnormalPic" placeholder="请输入异常图片" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="是否设备生成" prop="isEquipment">-->
<!--          <el-input v-model="hiddenDangerFrom.isEquipment" placeholder="请输入是否设备生成" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="隐患描述" prop="remark">
          <el-input v-model="hiddenDangerFrom.remark" placeholder="请输入隐患描述" style="width: 100%"></el-input>
        </el-form-item>
<!--        <el-form-item label="上报人" prop="reportPerson">-->
<!--          <el-input v-model="hiddenDangerFrom.reportPerson" placeholder="请输入上报人" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="上报时间" prop="reportTime">-->
<!--          <el-input v-model="hiddenDangerFrom.reportTime" placeholder="请输入上报时间" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="区域Id" prop="regionId">-->
<!--          <el-input v-model="hiddenDangerFrom.regionId" placeholder="请输入维保详情" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="执行人" prop="executePerson">-->
<!--          <el-input v-model="hiddenDangerFrom.executePerson" placeholder="请输入执行人" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="执行时间" prop="executeTime">-->
<!--          <el-input v-model="hiddenDangerFrom.executeTime" placeholder="请输入执行时间" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="分配时间" prop="allocateTime">-->
<!--          <el-input v-model="hiddenDangerFrom.allocateTime" placeholder="请输入分配时间" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="完成时间" prop="completeTime">-->
<!--          <el-input v-model="hiddenDangerFrom.completeTime" placeholder="请输入完成时间" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="反馈时间" prop="feedbackTime">-->
<!--          <el-input v-model="hiddenDangerFrom.feedbackTime" placeholder="请输入反馈时间" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="反馈描述" prop="feedbackRemark">-->
<!--          <el-input v-model="hiddenDangerFrom.feedbackRemark" placeholder="请输入反馈描述" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="审核时间" prop="examineTime">-->
<!--          <el-input v-model="hiddenDangerFrom.examineTime" placeholder="请输入审核时间" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="审核意见" prop="examineOpinion">-->
<!--          <el-input v-model="hiddenDangerFrom.examineOpinion" placeholder="请输入审核意见" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="审核状态" prop="examineStatus">-->
<!--          <el-input v-model="hiddenDangerFrom.examineStatus" placeholder="请输入审核状态" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="隐患状态" prop="status">-->
<!--          <el-input v-model="hiddenDangerFrom.status" placeholder="请输入隐患状态" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="完成图片" prop="completeUrl">-->
<!--          <el-input v-model="hiddenDangerFrom.completeUrl" placeholder="请输入完成图片" style="width: 100%"></el-input>-->
<!--        </el-form-item>-->
      </el-form>
    </div>
    <div slot="footer" style="text-align: center" class="dialog-footer">
      <el-button @click="cancelCommission">取消</el-button>
      <el-button :loading="addLoading" v-if="createStatus" type="primary" @click="addInHiddenDanger">创 建
      </el-button>
      <el-button :loading="addLoading" v-else type="primary" @click="updateInHiddenDanger">更新</el-button>
    </div>
  </div>
</template>

<script>

import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";
import {getInUserList} from "@/api/enterprise";
import {addInHiddenDanger, getInHiddenDanger, updateInHiddenDanger} from "@/api/hiddenDanger";
export default {
  name: "edit",
  data(){
    return{
      hiddenDangerFrom:{

      },
      hiddenDangerFromRules:{
        // designee: [{ required: true, message: '请选择指定人', trigger: 'blur' }],
        enterpriseId: [{ required: true, message: '请选择企业', trigger: 'blur' }],
        // equipmentId: [{ required: true, message: '请选择设备', trigger: 'blur' }],
      },
      addLoading:false,
      enterpriseList:[],
      executorList:[]
    }
  },
  computed: {
    createStatus(){
      return this.$route.query.ucId==undefined
    },
    enterPriseHidden(){
      let roleCode = this.$store.getters.roleCode;
      return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"||roleCode=="XZ-ADMIN"
    }
  },
  created() {
    if(!this.createStatus){
      let ucId =this.$route.query.ucId
      this.getInHiddenDanger(ucId)
    }
    this.getInEnterpriseDominantList();
    this.getInUserList();
  },
  methods:{
    cancelCommission(){
      window.history.back()
    },
    getInHiddenDanger(val) {
      getInHiddenDanger({ucId: val}).then(res =>{
        console.log(res)
        this.hiddenDangerFrom = res.data
      }).catch(res => {
        this.addLoading = false
        this.$notify.error({
          title: '失败',
          message: res.msg
        })
      })
    },
    addInHiddenDanger() {
      this.addLoading = true
      this.$refs['hiddenDangerFrom'].validate(valid => {
        if (valid) {
          addInHiddenDanger(this.hiddenDangerFrom).then(res => {
            this.addLoading = false
            this.$notify.success({
              title: '成功',
              message: "添加消防隐患信息成功"
            })
            this.cancelCommission()
          }).catch(res => {
            this.addLoading = false
            this.$notify.error({
              title: '失败',
              message: res.msg
            })
          })
        } else {
          this.addLoading = false
          console.log("表单验证不通过")
        }
      })
    },
    updateInHiddenDanger() {
      this.addLoading = true
      this.$refs['hiddenDangerFrom'].validate(valid => {
        if (valid) {
          updateInHiddenDanger(this.hiddenDangerFrom).then(res => {
            this.addLoading = false
            this.$notify.success({
              title: '成功',
              message: "更新消防隐患信息成功"
            })
            this.cancelCommission()
          }).catch(res => {
            this.addLoading = false
            this.$notify.error({
              title: '失败',
              message: res.msg
            })
          })
        } else {
          this.addLoading = false
          console.log("表单验证不通过")
        }
      })
    },
    getInEnterpriseDominantList() {
      getInEnterpriseDominantList({}).then(res => {
        this.enterpriseList=res.data;
      }).catch(res => {
        this.addLoading = false
        this.$notify.error({
          title: '失败',
          message: res.msg
        })
      })
    },
    getInUserList() {
      getInUserList({}).then(res => {
        this.executorList = res.data
        console.log(res.data)
      }).catch(res => {
        this.addLoading = false
        this.$notify.error({
          title: '失败',
          message: res.msg
        })
      })
    },

  }

}
</script>

<style
    scoped>

</style>